package com.huanletao.word;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestWord {
	public static void main(String[] args) throws Exception {
		 //需要进行文本替换的信息
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("date", "2021-03-11");
        data.put("name", "东方明珠");
        data.put("address", "北京华777ggggfSSS发鬼地方个东院");


        //需要进行动态生成的信息
        List<Object> mapList = new ArrayList<Object>();

        //第一个动态生成的数据列表
        List<String[]> list01 = new ArrayList<String[]>();
        list01.add(new String[]{"A","已还款","22.36","22.02"});
        list01.add(new String[]{"A","22222222222","33","22"});
        list01.add(new String[]{"B","33333333333","44","22"});
        list01.add(new String[]{"C","44444444444","55","22"});

        //第二个动态生成的数据列表
        List<String[]> list02 = new ArrayList<String[]>();
        list02.add(new String[]{"A","11111111111","广发银行","22222222222222222222222222","张三","未还款","就这些还得用我还吗"});
        list02.add(new String[]{"d","22222222222","33","22","11111111111","22","22"});
        list02.add(new String[]{"B","33333333333","44","22","11111111111","22","22"});
        list02.add(new String[]{"C","44444444444","55","22","11111111111","22","22"});

        mapList.add(list01);
        mapList.add(list02);

        //需要动态改变表格的位置；第一个表格的位置为0
        int[] placeList = {1,2};
        String sourceFile = "C:\\Users\\Administrator\\Desktop\\工作笔记\\20210602\\还款记录\\还款记录.docx";
        String sourceTOFile = "C:\\Users\\Administrator\\Desktop\\工作笔记\\20210602\\还款记录\\还款记录1.docx";
        XWPFDocument doc = WorderToNewWordUtils.changWord(sourceFile,data,mapList,placeList);
        FileOutputStream fopts = new FileOutputStream(sourceTOFile);
        doc.write(fopts);
        // 测试docx转pdf
        String pdfPath = "C:\\Users\\Administrator\\Desktop\\工作笔记\\20210602\\还款记录\\呵呵11.pdf";
       // OfficeUtil.docxToPdf(sourceTOFile,pdfPath);
        fopts.close();
	}
}
